package com.ad.pet.app.main.desniger.adapter;

import android.app.Activity;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ad.pet.R;
import com.ad.pet.app.Navigation;
import com.ad.pet.common.data.utils.DensityUtil;
import com.ad.pet.common.data.utils.glide.GlideUtil;
import com.ad.pet.common.data.utils.ui.ToastUtil;
import com.ad.pet.models.remote.main.DesingerMain;
import com.ad.pet.utils.LyxUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.library.flowlayout.FlowLayoutManager;
import com.library.flowlayout.SpaceItemDecoration;

import java.util.List;

/**
 * Created by SEELE on 2019/6/27.
 */

public class DesnigerShopListAdapter extends BaseQuickAdapter<DesingerMain, BaseViewHolder> {

    public DesnigerShopListAdapter(@Nullable List<DesingerMain> data) {
        super(R.layout.item_fujin_shop_layout, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, final DesingerMain item) {
        LinearLayout linearItem = helper.getView(R.id.linear_item);
        TextView tv_detail = helper.getView(R.id.tv_detail);
        TextView tv_address = helper.getView(R.id.tv_address);
        TextView tv_shopname = helper.getView(R.id.tv_shopname);
        TextView tv_juli = helper.getView(R.id.tv_juli);
        TextView tv_time = helper.getView(R.id.tv_time);
        RecyclerView recycler_fujin = helper.getView(R.id.recycler_fujin);
        ImageView iv_shop = helper.getView(R.id.iv_shop);

        tv_address.setText(item.getShop_name());
        tv_shopname.setText(item.getLive_store_address());
//        tv_juli.setText(item.getDistance() + "米");
        tv_time.setText(item.getShop_workingtime());
        GlideUtil.load(mContext, item.getShop_avatar(), iv_shop);

        FlowLayoutManager flowLayoutManager = new FlowLayoutManager();
        recycler_fujin.addItemDecoration(new SpaceItemDecoration(DensityUtil.dip2px(3)));
        recycler_fujin.setLayoutManager(flowLayoutManager);
        MyAdapter mMHirstoryAdapter = new MyAdapter(item.getList());
        recycler_fujin.setAdapter(mMHirstoryAdapter);
        double length = Double.valueOf(item.getDistance());
        String juli = "";
        if (length < 1000) {
            juli = length + "m";
        } else {
            juli = LyxUtils.formatDouble2(length / 1000) + "km";
        }
        tv_juli.setText("距离 " + juli);
        tv_detail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (item.getIs_redecorate() == 0) {
                    Navigation.goDesignerStore((Activity) mContext, item);
                }

            }
        });
//        if (item.getIs_redecorate()==1){
//            tv_detail.setVisibility(View.GONE);
//        }else {
//            tv_detail.setVisibility(View.VISIBLE);
//        }
        linearItem.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (item.getIs_redecorate() == 0) {
                    Navigation.goDesignerStore((Activity) mContext, item);
                }else {
                    ToastUtil.getToastUtil().showShort("门店筹备中，敬请期待");
                }
            }
        });
    }

    class MyAdapter extends BaseQuickAdapter<String, BaseViewHolder> {

        public MyAdapter(@Nullable List<String> data) {
            super(R.layout.item_shop_fujin_something_layout, data);
        }

        @Override
        protected void convert(BaseViewHolder helper, String item) {
            TextView tvName = helper.getView(R.id.tv_name);
            tvName.setText(item);

            if (helper.getLayoutPosition() % 2 == 0) {
                tvName.setBackgroundResource(R.drawable.shap_shop_fuji_main_color);
                tvName.setTextColor(mContext.getResources().getColor(R.color.shop_fujin_maincolor));
            } else {
                tvName.setBackgroundResource(R.drawable.shap_shop_fuji_fenhong_color);
                tvName.setTextColor(mContext.getResources().getColor(R.color.shop_fujin_fenhongcolor));
            }
        }
    }
}
